package com.lagou.homework;

import com.lagou.homework.annotation.AnnotationBeanNameGenerator;
import com.lagou.homework.annotation.AnnotationMetadata;
import com.lagou.homework.support.BeanDefinition;

import java.util.List;
import java.util.Properties;
import java.util.Set;

/**
 * @author boting.guo
 * @date 2021/9/18 23:56
 */

public class AnnotatedBeanDefinitionReader {

	private final DefaultListableBeanFactory registry;

	private final AnnotationBeanNameGenerator beanNameGenerator = new AnnotationBeanNameGenerator();

	public AnnotatedBeanDefinitionReader(DefaultListableBeanFactory registry) {
		this.registry = registry;
	}

	public void register(Class<?>... componentClasses) throws Exception {
		for (Class<?> componentClass : componentClasses) {
			registerBean(componentClass);
		}
	}

	public void registerBean(Class<?> beanClass) throws Exception {
		BeanDefinition beanDefinition = new BeanDefinition(beanClass);

		String beanName = beanNameGenerator.generateBeanName(beanDefinition);
		beanDefinition.setBeanName(beanName);

		this.registry.registerBeanDefinition(beanName, beanDefinition);
	}


}